from beanie import Document
from pydantic import Field, BaseModel
from datetime import datetime

class AuthCodeFields:

    code: str = Field()
    created_at: datetime = Field(default_factory=lambda: datetime.now())
    updated_at: datetime = Field(default_factory=lambda: datetime.now())


class AuthCodeModel(Document, AuthCodeFields):
    """
    微信用户表
    """
    class Collection:
        name = "auth_code"

    async def before_update(self):
        self.updated_at = datetime.now()

class AuthCodeCreate(BaseModel, AuthCodeFields):
    pass

class AuthCodeOut(BaseModel, AuthCodeFields):
    pass